function showFamilyOfTraces
% showFamilyOfTraces
%
% Intended use -- as userFcn for qvTrace
%
% Should be able to run this from any trace within the family.

% gs 2008 03 08
% ---------------------------------

currentTrace = evalin('base', 'currentTrace');

sr = currentTrace.header.ephys.ephys.sampleRate;

if ~strcmp(currentTrace.userFcn.fIAnalysis.familyType, 'cpu loop')
    % if strcmp(currentTrace.userFcn.fIAnalysis.familyType, 'daq loop')
    disp('showFamilyOfTraces: currently only works with cpu loops');
    return
end

Ntot = currentTrace.header.loopGui.loopGui.iterations;
Nseq = currentTrace.header.loopGui.loopGui.iterationCounter;
Nacq = str2num(currentTrace.header.xsg.xsg.acquisitionNumber);

[p, f, ext] = fileparts(currentTrace.userFcn.filename);
NfirstFile = Nacq - Nseq; 
% happens to come out right; Nacq actually seems to be for 
% the next, i.e., to-be-acq'd, trace

for n = 1 : Ntot
    newNum = num2str(NfirstFile + n - 1);
    nchar = numel(newNum);
    f(end-3:end) = '0000';
    ftemp = [f(1 : end - nchar) newNum];
    filename = fullfile(p, [ftemp, ext]);
    t = load(filename, '-mat');
    traceData(:,n) = t.data.ephys.trace_1;
end

figure('Name', [f(1:6) 'family'], 'NumberTitle', 'off', 'Color', 'w');
% colormap(jet(256));
colormap(flipud(hsv(256)));
% colormap(flipud(hot(256)));
% colormap(hot(256));
colormap(flipud(gray(256)));

subplot(2,1,1)
xdata = [0:size(traceData, 1)-1] / sr;
plot(xdata, traceData);
box off;
ylabel('mV');

subplot(2,1,2);
himg = imagesc(flipud(traceData'));
xlims = [xdata(1) xdata(end)];
set(himg, 'XData', xlims);
set(gca, 'CLim', [-100 0], 'XLim', xlims);
box off;
colorbar;
xlabel('Time (sec)');

